﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using lumo.display.object2D;
using Microsoft.Xna.Framework;

namespace lumo.display.animation2D
{
    /// <summary>
    /// The origin animation object
    /// </summary>
    public class OriginAnimation2D : GenericAnimation2D<IOriginable2D>
    {
        // Private variables
        private Vector2? From = null;
        private Vector2 To;
        private Counter OXCounter = new Counter();
        private Counter OYCounter = new Counter();

        /// <summary>
        /// Constructor
        /// </summary>
        public OriginAnimation2D(Vector2 To, float Time, Smooth Smoothness = Smooth.None, Loop LoopMode = Loop.None, IOriginable2D CurrentObject = null)
            : base(Time, Smoothness, LoopMode, CurrentObject)
        {
            this.To = To;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        public OriginAnimation2D(Vector2? From, Vector2 To, float Time, Smooth Smoothness = Smooth.None, Loop LoopMode = Loop.None, IOriginable2D CurrentObject = null)
            : base(Time, Smoothness, LoopMode, CurrentObject)
        {
            this.From = From;
            this.To = To;
        }

        /// <summary>
        /// Check if finished
        /// </summary>
        public override bool Finished { get { return (OXCounter.Finished && OYCounter.Finished); } }

        /// <summary>
        /// Setup the values
        /// </summary>
        internal override void SetupValues()
        {
            if (!this.From.HasValue)
                this.From = this.CurrentObject.Origin;
            OXCounter.Reset(this.From.Value.X, this.To.X, this.Time, this.Smoothness, this.LoopMode);
            OYCounter.Reset(this.From.Value.Y, this.To.Y, this.Time, this.Smoothness, this.LoopMode);
        }

        /// <summary>
        /// Update the values.
        /// </summary>
        /// <param name="Game">The game class</param>
        internal override void UpdateValues(LumoComponent Game)
        {
            OXCounter.Update(Game);
            OYCounter.Update(Game);
            this.CurrentObject.Origin = new Vector2(OXCounter.Value, OYCounter.Value);
        }
    }
}
